import { ref, computed } from 'vue'
import { useStore } from '@/store'
export const pageTable = () => {
    const store = useStore()
    const page = ref(1)
    const total = computed(() => {
        return store.list.length
    })
    const list = computed(() => {
        let tableList=JSON.parse(JSON.stringify(store.list))
        tableList.forEach(item=>{
            let arr=item.ip.split(".")
            let str=""
            arr.map(item=>{
                str+=item
            })
            item.sortKey=str
        })
        tableList.sort(fastSort)
        tableList.forEach(item=>{
            delete item.sortKey
        })
        let arr = []
        for (let i = (page.value - 1) * 10; i < (page.value * 10 > tableList.length ? tableList.length : page.value * 10); i++) {
            arr.push(tableList[i])
        }
        return arr
    })
    return { page, list, total }
}

function fastSort(a,b){
    return a.sortKey-b.sortKey
}